﻿using System;
using ContractManagementSystem.BusinessLogicLayer;
using ContractManagementSystem.EntityObjects;

// Assembly marked as compliant.
[assembly: CLSCompliant(true)]

public partial class CmsMaster : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        DisplayLogOff();
    }

    // Display link "Log Out" whenever Session["username"] is not null
    private void DisplayLogOff()
    {
        if (Session["UserName"] != null)
        {
            LinkLogOff.Text = Session["UserName"] + " [ Log Out ]";
        }
        else
        {
            LinkLogOff.Text = "";
            Response.Redirect(Page.Master.ResolveUrl("Presentation/LogOn.aspx"));
        }
    }

    protected void LogOffClick (object sender, EventArgs e)
    {
        // Save event of logging out
        var userEventEntity = new EventEntity
                                  {
                                      UserName = CommonLogic.ConvertToString(Session["UserName"]),
                                      OnDate = DateTime.Now,
                                      Description = "User logged out"
                                  };

        EventTracer.SaveEvents(userEventEntity);

        Session.Abandon();

        Response.Redirect(Page.Master.ResolveUrl("Presentation/LogOn.aspx"));
    }
}

